package com.zj.core.ui

import android.support.constraint.ConstraintLayout
import android.support.constraint.ConstraintLayout.LayoutParams.PARENT_ID
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.zj.core.R
import org.jetbrains.anko.*
import org.jetbrains.anko.constraint.layout.constraintLayout

class ItemListDetailUI: AnkoComponent<ViewGroup> {
    override fun createView(ui: AnkoContext<ViewGroup>): View =with(ui){
        constraintLayout {
            lparams(width= matchParent,height = wrapContent){
                leftMargin=dip(10)
                rightMargin=dip(10)
            }

            view{
                id=R.id.record_item_line
                visibility= View.GONE
                backgroundColor=resources.getColor(R.color.black_translucent)
            }.lparams(width= matchParent,height = dip(1)){
                topToTop=PARENT_ID
            }

            /**
             * constraintLayout的Margin无效，只能使用view占位
             */
            view {
                id= R.id.record_view
                visibility=View.INVISIBLE
            }.lparams(width= matchParent,height = dip(15)){
                topToBottom=R.id.record_item_line
            }

            textView {
                id= R.id.type_name_tv
                gravity= Gravity.RIGHT
                textSize=dip(10).toFloat()
                textColor=resources.getColor(R.color.colorsBlank)
            }.lparams(width=dip(50),height = wrapContent){
                leftToLeft= ConstraintLayout.LayoutParams.PARENT_ID
                topToBottom=R.id.record_view
            }

            linearLayout {
                id=R.id.parent_lly
                orientation=LinearLayout.VERTICAL

                textView {
                    id= R.id.type_value_tv
                    maxLines=1
                    textSize=dip(10).toFloat()
                    textColor=resources.getColor(R.color.colorsBlank)
                    gravity= Gravity.CENTER_HORIZONTAL
                }.lparams(width= matchParent,height = wrapContent)
            }.lparams(width=0,height = wrapContent){
                leftMargin=dip(5)
                rightMargin=dip(5)
                leftToRight= R.id.type_name_tv
                rightToLeft= R.id.push_img_view
                topToBottom=R.id.record_view
            }

            imageView {
                id= R.id.push_img_view
                visibility= View.INVISIBLE
                background=resources.getDrawable(R.mipmap.detail_img)
            }.lparams(width=dip(25),height = dip(25)){
                bottomToBottom= R.id.type_name_tv
                leftToRight= R.id.parent_lly
                rightToRight= ConstraintLayout.LayoutParams.PARENT_ID
                topToBottom=R.id.record_view
            }
        }
    }
}